﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Eb;

namespace Ec
{
    public class BotsConfig
    {
        //---------------------------------------------------------------------
        public string PluginDllFileName { get; private set; }
        public string PluginClassName { get; private set; }
        public string Ip { get; private set; }
        public int Port { get; private set; }

        //---------------------------------------------------------------------
        public BotsConfig()
        {
            string file_name = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string cfg_file = Path.Combine(file_name, "..\\Bots4StressTest.xml");
            cfg_file = Path.GetFullPath(cfg_file);

            bool exist_file = File.Exists(cfg_file);
            if (!exist_file)
            {
                EbLog.Error("Bots4StressTest配置文件不存在：" + cfg_file);
            }

            XmlDocument doc = new XmlDocument();
            doc.Load(cfg_file);

            XmlNodeList node_list = doc.GetElementsByTagName("Bots4StressTest");
            XmlElement node_root = (XmlElement)node_list[0];

            XmlElement el_plugin_info = node_root["PluginInfo"];
            PluginDllFileName = el_plugin_info.GetAttribute("DllFileName");
            PluginClassName = el_plugin_info.GetAttribute("ClassName");

            XmlElement el_acc_info = node_root["AccInfo"];
            Ip = el_acc_info.GetAttribute("Ip");
            Port = int.Parse(el_acc_info.GetAttribute("Port"));
        }
    }
}